package com.coollang.smartbra.presenter;

import com.coollang.smartbra.base.MyApplication;
import com.coollang.smartbra.bleutil.BleUtil;
import com.coollang.smartbra.bleutil.callback.BleCallbackImpl;
import com.coollang.smartbra.fragment.RunningSettingFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: Timmy
 * @Data: 2017/8/14
 * @Fuction:
 */

public class RunningSettingFragmentPresenter {

    private RunningSettingFragment mSettingFragment;
    public List<Integer> mHeartList = new ArrayList<>();

    public RunningSettingFragmentPresenter(RunningSettingFragment settingFragment) {
        mSettingFragment = settingFragment;
    }

    public void initBlutTooth() {

        // 开启心率开关
        BleUtil.getInstance().sendData((byte) 0x47);
        BleUtil.getInstance().registerNotifyListener(mBleCallback);
    }

    private BleCallbackImpl mBleCallback = new BleCallbackImpl() {
        @Override
        public void onBleConnected() {
            MyApplication.getApplication().sendDate();// 校准时间戳
        }

        @Override
        protected void onRunDataRecieved(long runTimes, long runSteps, int currentHeartRate) {

            if (currentHeartRate != 0) {
                // 存储心率
                mHeartList.add(currentHeartRate);
            }

            mSettingFragment.setStrpsAndHeart(runSteps, currentHeartRate);
        }

        @Override
        public void onActionZhengFan(byte zhengfan, byte qingxie) {
            mSettingFragment.showPromptDialog(zhengfan, qingxie);
        }
    };

    public void unBindBlueTooth() {
        // 关闭心率开关
        BleUtil.getInstance().sendData((byte) 0x47, (byte) 02);
        BleUtil.getInstance().unRegisterNotifyListener();
    }
}
